<?
//inculde即可以使用data数据。本页所有的data数据，倾在controller都处理好
include_once("../../../common/module/checkA.php");
include_once("../../../../config.php");
include_once("../controller/detail-add.php");
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php include ROOT_PATH_.'/controller/common/module/head.php'; ?>
    <link href="../asset/css/css.css" rel="stylesheet" type="text/css"/>
</head>

<body>

<div id="topbar">
    <?php include ROOT_PATH_.'/controller/common/module/topbar.php'; ?>
</div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controller/common/module/sidebar.php'; ?>
        </div>


        <div id="content">
            <?php $page_title='新建订单';?>
            <?php include ROOT_PATH_.'/controller/common/module/mod-page-title.php'; ?>



            <div class="make-order-box">
                <form class="layui-form" action="">




                    <hr/>

<!--                    产品一多的话，逐个选择就会非常之困难。所以要改变形式，先列出所有商品，需要的再打勾，也可以选择分类逐步筛选缩小。<br/>-->
                    <!--todo  产品一多的话，逐个选择就会非常之困难。所以要改变形式，先列出所有商品，需要的再打勾，也可以选择分类逐步筛选缩小。-->
<!---->
<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label">选择商品</label>-->
<!--                        <div class="layui-input-inline">-->
<!--                            <select name="product" lay-verify="required" lay-search="">-->
<!--                                <option value="">选择商品</option>-->
<!--                                --><?// foreach ($productList as $p=> $p_value){ ?>
<!--                                    <option value="--><?// echo $p_value['nid'].','.$p_value['price'].','.$p_value['name'];?><!--">--><?// echo $p_value['name']; ?><!--</option>-->
<!--                                --><?// }?>
<!--                            </select>-->
<!--                        </div>-->
<!--                    </div>-->
<!---->
<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label">商品数量</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="sum" placeholder="请输入数量"  autocomplete="off" class="layui-input" value="--><?// echo $_REQUEST['select_keywords']?><!--" >-->
<!--                        </div>-->
<!--                    </div>-->



                    <table class="layui-table">
                        <colgroup>
                            <col width=" ">
                            <col width=" ">
                            <col width="180">
                            <col width="100">
                            <col width="">
                            <col width="">
                            <col width="60">
                            <col width="60">

                        </colgroup>
                        <thead>
                        <tr>
                            <th>图片</th>
                            <th>名字</th>
                            <th>型号</th>
                            <th>价格</th>
                            <th>最低起订</th>
                            <th>库存</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        <?php

                        if ($detailnum == 0) {
                            echo "<tr><td colspan='6'>暂无数据</td></tr>";
                        }

                        for ($i = 0; $i < $detailnum; $i++) {
                            ?>

                            <tr id="item<?echo $detail[$i]['nid']?>" >

                                <td>
                                    <div class="icon" style="background-image: url('/uploadfiles/uf<?echo $site['mid']?>/<?echo $detail[$i]['icon']?>')"></div>
                                </td>
                                <td><? echo $detail[$i]['name']?></td>
                                <td><? echo $detail[$i]['model']?></td>

                                <td><? echo $detail[$i]['price']?></td>
                                <td><? echo $detail[$i]['zuidiqiding']?></td>
                                <td><? echo $detail[$i]['storage']?></td>

                                <!--          <td>--><?// echo $detail[$i]['publish'] == 1 ? '显示' : '隐藏'?><!--</td>-->

                                <td>
                                    <button type="button" class="menu_<?php echo $detail[$i]['nid'];?> layui-btn layui-btn-sm <? echo $detail[$i]['publish'] == 1 ? '' : 'layui-btn-danger'?>"
                                            onclick="update_status(<?php echo $detail[$i]['nid'];?>)" >
                                        <? echo $detail[$i]['publish'] == 1 ? '显示' : '隐藏'?>
                                    </button>
                                </td>
                                <td>
                                    <button type="submit" class="layui-btn layui-btn-sm" >添加</button>

                                </td>
                            </tr>
                            <?php

                        }
                        ?>


                        </tbody>
                    </table>




                </form>
            </div>











            <div class="order-preview-box">

                <div class="layui-form-item">
                    <label class="layui-form-label">选择客户</label>
                    <div class="layui-input-inline">
                        <select name="unit"   lay-search="">
                            <option value="">选择客户</option>
                            <? foreach ($unitList as $x=> $x_value){ ?>
                                <option value="<? echo $x_value['nid'].','.$x_value['name'];?>"><? echo $x_value['name']; ?></option>
                            <? }?>
                        </select>
                    </div>
                </div>
            </div>


            <div class="detail-box layui-form">
                <div class="function">
                    <a class="layui-btn  layui-btn-sm" href="javascript:;" onclick="config_oder('<? echo $detail['nid']?>//')">确认订单</a>
                </div>
            </div>



        <br class="clearfloat" />
        <!--content端點01-->
        </div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>


<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?>

    <script>
        layui.use(['table','form'], function(){
            var form = layui.form;
            var table = layui.table;
            var tableData = [];
            //监听提交
            form.on('submit(addProduct)', function(data){
                layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                })
                var unitList =  data.field.unit.split(",");
                var productList =  data.field.product.split(",");
                tableData.push({unit:unitList[1],product:productList[2],price:productList[1],'sum':data.field.sum})
                //展示已知数据
                table.render({
                    elem: '#order-preview'
                    ,cols: [[ //标题栏
                        {field: 'unit', title: '客户', width: 200}
                        ,{field: 'product', title: '商品', width: 300}
                        ,{field: 'price', title: '金额', width: 150}
                        ,{field: 'sum', title: '数量', width: 100}
                    ]]
                    ,data: tableData
                    ,even: true
                });

                return false;
            });




        });
    </script>


<script>

	function save_client (name,phone) {

		con=confirm("确认保存客户?");
		if(con==true){
			$.ajax({
				type:"POST",
				url:"ajax_save.php",
				dateType:"json",
				data:{"act":'client',"name":name,"phone":phone},
				dataType:"json",
				beforeSend: function () {
					layer.msg('正在检查状态中');
				},
				success:function(data){

					if(data.error == 1){
						layer.msg(data.message, {icon: 2});
					}
					else if(data.error == 0){
						layer.msg(data.message, {icon: 1});

					}
				}
			})

		}

	}

	function save_unit (shuihao,address) {

		con=confirm("确认保存企业?");
		if(con==true){
			$.ajax({
				type:"POST",
				url:"ajax_save.php",
				dateType:"json",
				data:{"act":'unit',"shuihao":name,"address":address},
				dataType:"json",
				beforeSend: function () {
					layer.msg('正在检查状态中');
				},
				success:function(data){

					if(data.error == 1){
						layer.msg(data.message, {icon: 2});
					}
					else if(data.error == 0){
						layer.msg(data.message, {icon: 1});

					}
				}
			})

		}

	}


    function cancel_oder (id) {

        con=confirm("确认取消订单?");
        if(con==true){

			if(!id > 0 ){
				layer.msg('请刷新后再操作！');
				return false;
			}

			$.ajax({
				type:"POST",
				url:"cancel.php",
				dateType:"json",
				data:{"nid":id},
                dataType:"json",
				beforeSend: function () {
                      layer.msg('正在检查状态中');

               	},
				success:function(data){

						if(data.error == 1){
							layer.msg(data.content, {icon: 2});
						}
						else if(data.error == 0){
							layer.msg(data.content, {icon: 1});

						}
						window.location.reload();//刷新当前页面.
				}
			})


        }

    }



    function config_oder (id) {
		var collection_date = $('#collection_date').val();
		var remark = $('#remark').val();
		if(collection_date == ""){
			layer.msg('请选择付款时间');
			return;
		}
        con=confirm("确认出单吗?");
        if(con==true){

			if(!id > 0 ){
				layer.msg('请刷新后再操作！');
				return false;
			}

			$.ajax({
				type:"POST",
				url:"config_order.php",
				dateType:"json",
				data:{"nid":id,"collection_date" : collection_date,"remark" : remark},
                dataType:"json",
				beforeSend: function () {
                      layer.msg('正在检查状态中');

               	},
				success:function(data){

						if(data.error == 1){
							layer.msg(data.content, {icon: 2});
						}
						else if(data.error == 0){
							layer.msg(data.content, {icon: 1});
							window.location.reload();//刷新
						}

				}
			})


        }

    }

</script>


</body>
</html>
